<template>
  <div class="add-form">
    <el-dialog title="修改用户" :visible.sync="adds" width="50%">
      <el-form :model="addForm" :rules="addFormRules" ref="addFormRef" label-width="70px">
        <el-form-item label="企业名称" prop="company" label-width="100px">
          <el-input v-model="addForm.company"></el-input>
        </el-form-item>

        <el-form-item label="所属公司" prop="shortName" label-width="100px">
          <el-input v-model="addForm.shortName"></el-input>
        </el-form-item>
        <el-form-item label="城市" prop="province">
          <el-select v-model="addForm.province" placeholder="请选择" @change="cityChange(addForm.province)">
            <el-option v-for="item in cs" :key="item" :label="item" :value="item"> </el-option>
          </el-select>
          <el-select v-model="addForm.city" placeholder="请选择" collapse-tags style="margin-left: 20px">
            <el-option v-for="item in cityList" :key="item" :label="item" :value="item"> </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="方向(企业标签)" prop="tags" label-width="135px">
          <el-input v-model="addForm.tags"></el-input>
        </el-form-item>
        <el-form-item label="备注" prop="remarks"> <el-input type="textarea" autosize placeholder="请输入内容" v-model="addForm.remarks"> </el-input></el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="adds = false">取 消</el-button>
        <el-button type="primary" @click="addSubmit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { provinces, citys } from '../../api/hmmm/citys'
import { list, remove, update, add, disabled } from '../../api/hmmm/companys'
export default {
  name: 'CompanysAdd',
  props: {
    add: {
      type: Boolean,
      required: true
    }
  },
  data() {
    return {
      cityList: [],
      adds: this.add,
      addForm: {
        id: '',
        number: '',
        isFamous: false,
        shortName: '',
        company: '',
        province: '',
        city: '',
        tags: '',
        remarks: ''
      },
      addFormRules: {
        company: [{ required: true, message: '请输入内容', trigger: 'blur' }],
        shortName: [{ required: true, message: '请输入内容', trigger: 'blur' }],
        province: [{ required: true, message: '请输入内容', trigger: 'blur' }],
        tags: [{ required: true, message: '请输入内容', trigger: 'blur' }],
        remarks: [{ required: true, message: '请输入内容', trigger: 'blur' }]
      }
    }
  },
  computed: {
    cs: provinces
  },
  methods: {
    cityChange(val) {
      // console.log(val)
      this.cityList = citys(val)
      // console.log(this.cityList)
    },
    async addSubmit() {
      this.$refs.addFormRef.validate(async (valid) => {
        if (!valid) return
        //  发送请求完成添加用户的操作
        let res = await add(this.addForm)
        // 判断如果添加失败，就做提示
        // console.log(res)
        if (res.status !== 200) return this.$message.error('添加失败')
        // 添加成功的提示
        this.$message.success('添加成功')
        // 重新请求最新的数据
        // this.getOrderList()
        this.$emit('close')
        // 关闭对话框
        this.adds = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
